//
//  HREditUserInfoViewController.m
//  Hear
//
//  Created by mac on 2017/4/12.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HREditUserInfoViewController.h"
#import "SDCycleScrollView.h"
#import <TPKeyboardAvoidingScrollView.h>
#import "HRSelectIconViewController.h"
#import "YYPhotoGroupView.h"
//#import "MyPlayTool.h"
#import "HRRecordAudioViewController.h"

#import "HRDynamicCell.h"
#import "HRCoverImageModel.h"
#import "VPImageCropperViewController.h"
#import "OSSImageUploader.h"
#import "MBProgressHUD+assistant.h"
#import "UzysImagePickerController.h"
#import "HRShowLabelView.h"
#import "HRUserLabelModel.h"
#import "UIButton+SSEdgeInsets.h"
#import "ZHDatePickerView.h"
@interface HREditUserInfoViewController ()<SDCycleScrollViewDelegate,UIAlertViewDelegate,UzysImagePickerControllerDelegate,VPImageCropperDelegate,ZHDatePickerViewDelegate>
@property (nonatomic, strong)SDCycleScrollView *headScrollView;
@property (nonatomic, strong)UIImageView *iconImageView;
@property (nonatomic, strong)TPKeyboardAvoidingScrollView *myScrollView;
@property (nonatomic, copy)NSString *selectIconName;
@property (nonatomic, copy)NSString *selectIconColor;
@property (nonatomic, strong)UIButton *nickNameButton;
@property (nonatomic, strong)NSArray *coverArr;
@property (nonatomic, strong)HRSoundButton *soundButton;
@property(nonatomic, strong)UIButton *label1Button;
@property(nonatomic, strong)UIButton *label2Button;
@property(nonatomic, strong)UIButton *label3Button;
@property(nonatomic, strong)NSMutableArray *labelContentArr;
@property(nonatomic, strong)NSArray *selectLabelArr;
@property(nonatomic, strong)UIButton *ageButton;

@end

@implementation HREditUserInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"编辑资料";
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.labelContentArr = [NSMutableArray array];
    [self setupView];
}

- (void)setupView{
    self.myScrollView = [[TPKeyboardAvoidingScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.myScrollView];
    
    
   WeakSelf
    
    UILabel *iconLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 80, 20)];
    iconLabel.text = @"我的头像";
    iconLabel.textColor = FirstTextColor;
    iconLabel.font = CustomUIFont(16);
    [self.myScrollView addSubview:iconLabel];
    
    
    UIImageView *iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kFullWidth-80, 10, 60, 60)];
    iconImageView.layer.cornerRadius = 30;
    iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    iconImageView.clipsToBounds = YES;
    [self.myScrollView addSubview:(self.iconImageView = iconImageView)];
//    iconImageView.image = [HRCoverImageModel OriginImage:[UIImage imageNamed:ICONNAME] scaleToSize:weakSelf.iconImageView.size];
    
    
    
    if ([ICONCOLOR length]){
        [HRCoverImageModel OriginImage:[UIImage imageNamed:ICONNAME] scaleToSize:CGSizeMake(75, 75) callBackOriginImage:^(UIImage *originImage) {
            weakSelf.iconImageView.image = originImage;
        }];
        self.iconImageView.backgroundColor = [UIColor colorWithHexString:ICONCOLOR];
    }else{
        [self.iconImageView setImageWithURL:[NSURL URLWithString:ICONNAME] placeholder:[UIImage imageNamed:@""]];
    }

    
    iconImageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakSelf selectIconClock];
    }];
    [iconImageView addGestureRecognizer:tap];
    
    
    
    UILabel *line1 = [[UILabel alloc] initWithFrame:CGRectMake(0, iconImageView.bottom+10, kFullWidth, 0.5)];
    line1.backgroundColor = CustomColor(240, 240, 240, 1);
    [self.myScrollView addSubview:line1];
    
    
    CGFloat topPading = 15;
    
    
    UILabel *nickLabel = [[UILabel alloc] initWithFrame:CGRectMake(iconLabel.left, line1.bottom+topPading, 80, 20)];
    
    nickLabel.text = @"昵称";
    nickLabel.textColor = FirstTextColor;
    nickLabel.font = CustomUIFont(16);
    [self.myScrollView addSubview:nickLabel];
    
    
    CGFloat nicknameWidth = [NICKNAME sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}].width;
    self.nickNameButton = [[UIButton alloc] initWithFrame:CGRectMake(kFullWidth-nicknameWidth-20, nickLabel.top, nicknameWidth, 20)];
    [self.nickNameButton setTitle:NICKNAME forState:UIControlStateNormal];
    [self.nickNameButton setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
    self.nickNameButton.titleLabel.font = CustomUIFont(14);
    [self.nickNameButton addTarget:self action:@selector(nickNameButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.myScrollView addSubview:self.nickNameButton];
    self.nickNameButton.titleLabel.textAlignment = 2;

    
    
    UILabel *line2 = [[UILabel alloc] initWithFrame:CGRectMake(0, nickLabel.bottom+topPading, kFullWidth, 0.5)];
    line2.backgroundColor = CustomColor(240, 240, 240, 1);
    [self.myScrollView addSubview:line2];
    
    
    UILabel *hearIdLabel = [[UILabel alloc] initWithFrame:CGRectMake(iconLabel.left, line2.bottom+topPading, 80, 20)];
    hearIdLabel.text = @"Hearer ID";
    hearIdLabel.textColor = FirstTextColor;
    hearIdLabel.font = CustomUIFont(16);
    [self.myScrollView addSubview:hearIdLabel];

    
    
    UILabel *showHearIdLabel = [[UILabel alloc] initWithFrame:CGRectMake(kFullWidth-100, hearIdLabel.top, 80, 20)];
    showHearIdLabel.text = self.hearIdStr;
    showHearIdLabel.textColor = TEXTCOLOR;
    showHearIdLabel.font = CustomUIFont(16);
    [self.myScrollView addSubview:showHearIdLabel];
    showHearIdLabel.textAlignment = NSTextAlignmentRight;
    
    UILabel *line3 = [[UILabel alloc] initWithFrame:CGRectMake(0, showHearIdLabel.bottom+topPading, kFullWidth, 0.5)];
    line3.backgroundColor = CustomColor(240, 240, 240, 1);
    [self.myScrollView addSubview:line3];
    
    
    UILabel *ageLabel = [[UILabel alloc] initWithFrame:CGRectMake(iconLabel.left, line3.bottom+topPading, 80, 20)];
    ageLabel.text = @"出生日期";
    ageLabel.textColor = FirstTextColor;
    ageLabel.font = CustomUIFont(16);
    [self.myScrollView addSubview:ageLabel];
    
    
    UIButton *ageButton = [UIButton buttonWithType:0];
    [ageButton addTarget:self action:@selector(ageButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.myScrollView addSubview:(self.ageButton=ageButton)];
    ageButton.frame = CGRectMake(ageLabel.right, line3.bottom, kFullWidth-ageLabel.right, ageLabel.height+topPading*2);
    [ageButton setTitleColor:FirstTextColor forState:0];
    ageButton.titleLabel.font = CustomUIFont(16);
    ageButton.titleLabel.textAlignment = 2;

    UILabel *line4 = [[UILabel alloc] initWithFrame:CGRectMake(0, ageLabel.bottom+topPading, kFullWidth, 5)];
    line4.backgroundColor = CustomColor(240, 240, 240, 1);
    [self.myScrollView addSubview:line4];
    
    
    UILabel *showLabel = [[UILabel alloc] initWithFrame:CGRectMake(iconLabel.left, line4.bottom+topPading, 80, 20)];
    showLabel.text = @"个性标签";
    showLabel.textColor = FirstTextColor;
    showLabel.font = CustomUIFont(16);
    [self.myScrollView addSubview:showLabel];
    
    UIButton *labelBackButton = [UIButton buttonWithType:0];
    [labelBackButton addTarget:self action:@selector(labelBackButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.myScrollView addSubview:labelBackButton];
    labelBackButton.frame = CGRectMake(0, line4.bottom, kFullWidth, showLabel.height+topPading*2);
    
    self.label1Button = [UIButton buttonWithType:0];
    [self.label1Button setTitleColor:FirstTextColor forState:0];
    self.label1Button.titleLabel.font = CustomUIFont(13);
    [self.myScrollView addSubview:self.label1Button];
    self.label1Button.layer.cornerRadius = 3;
    self.label1Button.layer.borderWidth = 1;
    self.label1Button.layer.borderColor = FirstTextColor.CGColor;
    self.label1Button.frame = CGRectMake(kFullWidth-60-topPading, showLabel.top, 60, 20);
    self.label1Button.enabled = NO;
    self.label2Button = [UIButton buttonWithType:0];
    [self.label2Button setTitleColor:FirstTextColor forState:0];
    self.label2Button.titleLabel.font = CustomUIFont(13);
    [self.myScrollView addSubview:self.label2Button];
    self.label2Button.layer.cornerRadius = 3;
    self.label2Button.layer.borderWidth = 1;
    self.label2Button.layer.borderColor = FirstTextColor.CGColor;
    self.label2Button.frame = CGRectMake(self.label1Button.left-self.label1Button.width-5, self.label1Button.top, self.label1Button.width, self.label1Button.height);
    self.label2Button.enabled = NO;

    
    self.label3Button = [UIButton buttonWithType:0];
    [self.label3Button setTitleColor:FirstTextColor forState:0];
    self.label3Button.titleLabel.font = CustomUIFont(13);
    [self.myScrollView addSubview:self.label3Button];
    self.label3Button.layer.cornerRadius = 3;
    self.label3Button.layer.borderWidth = 1;
    self.label3Button.layer.borderColor = FirstTextColor.CGColor;
    self.label3Button.frame = CGRectMake(self.label2Button.left-self.label1Button.width-5, self.label1Button.top, self.label1Button.width, self.label1Button.height);
    self.label3Button.enabled = NO;


    UILabel *line5 = [[UILabel alloc] initWithFrame:CGRectMake(0, showLabel.bottom+topPading, kFullWidth, 0.5)];
    line5.backgroundColor = CustomColor(240, 240, 240, 1);
    [self.myScrollView addSubview:line5];
    
//    UILabel *soundLabel = [[UILabel alloc] initWithFrame:CGRectMake(iconLabel.left, line4.bottom+25, 110, 20)];
//    soundLabel.text = @"我的留声机";
//    soundLabel.textColor = FirstTextColor;
//    soundLabel.font = CustomUIFont(16);
//    [self.myScrollView addSubview:soundLabel];

    
    
//    UIButton *changeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.width-80, line4.bottom+20, 80, 30)];
//    [changeBtn setTitle:@"重新录制" forState:UIControlStateNormal];
//    [changeBtn setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
//    changeBtn.titleLabel.font = CustomUIFont(13);
//    [changeBtn addTarget:self action:@selector(changeBtnClick) forControlEvents:UIControlEventTouchUpInside];
//    [self.myScrollView addSubview:changeBtn];
//
//    HRSoundButton *soundButton = [HRSoundButton buttonWithType:0];
//    soundButton.frame = CGRectMake(kFullWidth-190, changeBtn.top, 150, 50);
//    soundButton.soundUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"SoundUrl"];
//    soundButton.hidden = ![soundButton.soundUrl length];
//    [self.myScrollView addSubview:(self.soundButton = soundButton)];
//    soundButton.right = changeBtn.left;
//    soundButton.leftImageView.frame = CGRectMake(15, 10, 13, 18);
//    soundButton.voiceImageView.frame = CGRectMake(soundButton.leftImageView.right+10, 12, 20, 15);
//    soundButton.voiceTimeLabel.frame = CGRectMake(soundButton.voiceImageView.right, -5, soundButton.width-soundButton.voiceImageView.right-15, soundButton.height);
//    [soundButton setImage:[UIImage imageNamed:@"语音播放长条"] forState:0];
    
    self.label1Button.hidden = YES;
    self.label2Button.hidden = YES;
    self.label3Button.hidden = YES;
    NSArray *userTagsArr = [[[NSUserDefaults standardUserDefaults] objectForKey:@"UserTags"] jsonValueDecoded];
    for (int i =0; i <userTagsArr.count; i ++) {
        if (i ==0){
            self.label1Button.hidden = NO;
            [self.label1Button setTitle:userTagsArr[i] forState:0];
        }else if (i ==1){
            self.label2Button.hidden = NO;
            [self.label2Button setTitle:userTagsArr[i] forState:0];
        }else{
            self.label3Button.hidden = NO;
            [self.label3Button setTitle:userTagsArr[i] forState:0];
        }
    }
}





- (void)changeBtnClick{
    HRRecordAudioViewController *audioVC = [HRRecordAudioViewController new];
    audioVC.isSound = YES;
    [self.navigationController pushViewController:audioVC animated:YES];
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.hidesBottomBarWhenPushed = YES;

    
    self.coverArr = [_infoModel.UserCoverPicture jsonValueDecoded];
    self.headScrollView.imageURLStringsGroup = self.coverArr;
    
    self.soundButton.soundUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"SoundUrl"];
    
    NSString *birthday = [[NSUserDefaults standardUserDefaults] objectForKey:@"Birthday"];
    if (birthday.length>10){
        [self.ageButton setTitle:[NSString stringWithFormat:@"%@",[birthday substringToIndex:10]] forState:0];
    }else{
        [self.ageButton setTitle:birthday forState:0];
    }
//    [self.ageButton setTitle:self.infoModel.Birthday forState:0];
    [self.ageButton setEdgeInsetsWithType:SSEdgeInsetsTypeTitle marginType:SSMarginTypeRight margin:20];
}

#pragma 更改标签
- (void)labelBackButtonClick{
    if (!self.labelContentArr.count){
        NSArray *contentArr;
        if ([self.infoModel.Sex intValue] ==1){
            contentArr = [[NSUserDefaults standardUserDefaults] objectForKey:@"manTagList"];
        }else{
            contentArr = [[NSUserDefaults standardUserDefaults] objectForKey:@"womanTagList"];
        }
        
        
        for (NSString *str in contentArr) {
            HRUserLabelModel *model = [HRUserLabelModel new];
            model.content = str;
            [self.labelContentArr addObject:model];
        }
    }
    
    WeakSelf
    [HRShowLabelView showLabelView:self.labelContentArr selectIndexBlock:^(NSArray *selectArr) {
        if (selectArr.count >3){
            [MBProgressHUD showMessage:@"标签不能超过三个" finishBlock:nil];
        }
        weakSelf.selectLabelArr = selectArr;
        weakSelf.label1Button.hidden = YES;
        weakSelf.label2Button.hidden = YES;
        weakSelf.label3Button.hidden = YES;
        
        for (int i =0; i < weakSelf.selectLabelArr.count; i++) {
            if (i == 0){
                [weakSelf.label1Button setTitle:weakSelf.selectLabelArr[i] forState:0];
                weakSelf.label1Button.hidden = NO;
            }else if (i == 1){
                [weakSelf.label2Button setTitle:weakSelf.selectLabelArr[i] forState:0];
                weakSelf.label2Button.hidden = NO;
            }else if (i ==2){
                [weakSelf.label3Button setTitle:weakSelf.selectLabelArr[i] forState:0];
                weakSelf.label3Button.hidden = NO;
            }
        }
        
        [weakSelf putToServer:[self.selectLabelArr jsonStringEncoded] andType:@"12"];
    }];
}




- (void)clickImageAtIndex:(NSUInteger)index{
    UIView *fromView = nil;
    NSMutableArray *items = [NSMutableArray new];
    NSArray *pics = self.coverArr;
    
    for (NSUInteger i = 0, max = pics.count; i < max; i++) {
        UIView *imgView = self.headScrollView.picViews[i];
        YYPhotoGroupItem *item = [YYPhotoGroupItem new];
        item.thumbView = imgView;
        item.largeImageURL = [NSURL URLWithString:pics[i]];
        item.largeImageSize = CGSizeMake(imgView.width, imgView.height);
        [items addObject:item];
        if (i == index) {
            fromView = imgView;
        }
    }
    
    YYPhotoGroupView *v = [[YYPhotoGroupView alloc] initWithGroupItems:items];
    [v presentFromImageView:fromView toContainer:self.navigationController.view animated:YES completion:nil];
}


- (void)nickNameButtonClick
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入新的个性签名" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertView.alertViewStyle=UIAlertViewStylePlainTextInput;
    UITextField *textField = [alertView textFieldAtIndex:0];
    textField.text = self.nickNameButton.titleLabel.text;
    [alertView show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1){
        UITextField *textField = [alertView textFieldAtIndex:0];
        if (textField.text.length < 2 || textField.text.length > 20)
        {
            [MBProgressHUD showMessage:@"请输入2-20字符长度的个性签名" finishBlock:nil];
        }else{
            [self putToServer:textField.text andType:@"2"];
        }
        
    }
}

- (void)putToServer:(NSString *)value andType:(NSString *)type{
    [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"cacheTime"];
    YTKApi *api = [YTKApi apiPutWithUrl:@"UserInfo/Put_UpdateUserInfo" para:@{@"LocalId":USERID,@"Value":value,@"UserUpdateType":type}];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            NSDictionary *dict = request.responseObject;
            [[NSUserDefaults standardUserDefaults] setObject:dict[@"BodyContent"] forKey:@"userInfo"];
            if([type intValue] == 4){
                [[NSUserDefaults standardUserDefaults] setObject:value forKey:@"iconName"];
            }else if ([type intValue] == 5){
                [[NSUserDefaults standardUserDefaults] setObject:value forKey:@"iconColor"];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [MBProgressHUD showMessage:@"修改成功" finishBlock:nil];

                if ([type intValue] == 2){
                    if (self.nickNameButton){
                        CGFloat nicknameWidth = [value sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}].width;
                        self.nickNameButton.width = nicknameWidth;
                        self.nickNameButton.left = kScreenWidth-nicknameWidth-20;
                        [self.nickNameButton setTitle:value forState:0];
                    }

                    [[NSUserDefaults standardUserDefaults] setObject:value forKey:@"nickName"];

                    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadIconAndBackGroundNotififation" object:nil];
                }else if ([type intValue] == 4){
                    if (self.iconImageView){
                        [self.iconImageView setImageWithURL:[NSURL URLWithString:value] placeholder:[UIImage imageNamed:@""]];
                    }
                    
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadIconAndBackGroundNotififation" object:nil];
                }else if ([type intValue] == 12){
                    [[NSUserDefaults standardUserDefaults] setObject:value forKey:@"UserTags"];
                }else if ([type intValue] == 11){
                    [[NSUserDefaults standardUserDefaults] setObject:value forKey:@"Birthday"];
                }
 
                
            });
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        }];
    }];
}



- (void)postInfoClick{
    
    if(!self.selectIconName.length) return;
}

- (void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)selectIconClock{
    
    
    UzysImagePickerController * UzysImageP = [[UzysImagePickerController alloc] init];
    [UzysImageP showInViewContrller:self maxCount:1 delegate:self];
    
    
}


- (void)UzysImagePickerDidFinishWithImages:(NSArray *)imageArray{
    dispatch_async(dispatch_get_main_queue(), ^{
        VPImageCropperViewController *imgCropperVC = [[VPImageCropperViewController alloc] initWithImage:[self getBigIamgeWithALAsset:[imageArray firstObject]] cropFrame:CGRectMake(0, 100, kFullWidth, kFullWidth) limitScaleRatio:3.0];
        imgCropperVC.delegate = self;
        [self presentViewController:imgCropperVC animated:YES completion:nil];
    });
}

- (UIImage*)getBigIamgeWithALAsset:(UIImage *)set{
    //压缩
    NSData *imageData = UIImageJPEGRepresentation(set, 0.5);
    return [UIImage imageWithData:imageData];
}


- (void)imageCropper:(VPImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage{
    
    WeakSelf
    dispatch_async(dispatch_get_main_queue(), ^{
        [cropperViewController dismissViewControllerAnimated:YES completion:nil];
        
        [OSSImageUploader asyncUploadImage:editedImage complete:^(NSArray<NSString *> *names, UploadImageState state) {
            if (state == UploadImageFailed){
                [MBProgressHUD hideHUDForView:WINDOW animated:YES];
                return;
            }
            NSString *picUrl = [NSString stringWithFormat:@"http://%@.%@%@",BucketName,AliYunHost,[names firstObject]];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf putToServer:picUrl andType:@"4"];

                [weakSelf putToServer:@"" andType:@"5"];

            });
        }];
        
        
        
    });
}


- (void)imageCropperDidCancel:(VPImageCropperViewController *)cropperViewController{
    dispatch_async(dispatch_get_main_queue(), ^{
        [cropperViewController dismissViewControllerAnimated:YES completion:nil];
    });
}

- (void)ageButtonClick{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd";
    NSString *string = [formatter stringFromDate:date];
    NSDate *date2 = [formatter dateFromString:@"1990-09-09"];
    ZHDatePickerView *pickerView = [[ZHDatePickerView alloc] initDatePickerWithDefaultDate:date2
                                                                         andDatePickerMode:UIDatePickerModeDate];
    
    pickerView.delegate = self;
    [pickerView show];
}

- (void)pickerView:(ZHDatePickerView *)pickerView didSelectDateString:(NSString *)dateString {
    NSString *subStr = [dateString substringToIndex:4];
    if ([subStr intValue]< 1960 || [subStr intValue] > 2001){
        [MBProgressHUD showMessage:@"年龄不在范围内" finishBlock:nil];
        return;
    }
    [self.ageButton setTitle:dateString forState:UIControlStateNormal];
    
    [self putToServer:dateString andType:@"11"];
}




-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSUserDefaults standardUserDefaults] setInteger:300 forKey:@"cacheTime"];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"stopPlayVoiceNotification" object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
